#include <QMessageBox>

#include "createnewtorrent.h"
#include "mainwindowimpl.h"
#include "addtorrentfromurl.h"
#include "addrssfeed.h"
//
MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f) 
	: QMainWindow(parent, f)
{
	setupUi(this);

	frameDiskStatistics_show_hide();

	//connect(actionShow_Toolbar, SIGNAL(toggled(bool)), toolBar, SLOT(setVisible(bool)));//F4
	//connect(actionShow_Detailed_Info, SIGNAL(changed()), this, SLOT(tabDetailedInfo_show_hide()));//F5
	//connect(actionShow_Status_Bar, SIGNAL(changed()), this, SLOT(statusbar_show_hide()));//F6
	//connect(actionShow_Category_List, SIGNAL(changed()), this, SLOT(categoryList_show_hide()));//F7

	createNewTorrent = 0;
	addRSSFeed = 0;
	connect(action_Create_New_Torrent, SIGNAL(triggered()), this, SLOT(newTorrent()));
	connect(actionAdd_Torrent_from_URL, SIGNAL(triggered()), this, SLOT(fromURL()));
	connect(actionAdd_RSS_feed, SIGNAL(triggered()), this, SLOT(rssFeed()));

	connect(comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(frameDiskStatistics_show_hide()));

	connect(action_About_LinTorrent, SIGNAL(triggered()), this, SLOT(about()));
	connect(actionAbout_QT, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
}

// Слоты
/* void MainWindowImpl::toolbar_show_hide() //F4
{
	toolBar->setVisible(actionShow_Toolbar->isChecked());
}
void MainWindowImpl::tabDetailedInfo_show_hide() //F5
{
	tabDetailedInfo->setVisible(actionShow_Detailed_Info->isChecked());
}
void MainWindowImpl::statusbar_show_hide() //F6
{
	statusbar->setVisible(actionShow_Status_Bar->isChecked());
}
void MainWindowImpl::categoryList_show_hide() //F7
{
	categoryList->setVisible(actionShow_Category_List->isChecked());
} */

void MainWindowImpl::newTorrent()
{
	if (!createNewTorrent) {
		createNewTorrent = new CreateNewTorrent(this);
		//createNewTorrent->setAttribute(Qt::WA_DeleteOnClose);
	}
	createNewTorrent->show();
	createNewTorrent->activateWindow();
}

void MainWindowImpl::fromURL()
{
	AddTorrentFromURL *fromURLDialog = new AddTorrentFromURL(this);
	fromURLDialog->exec();
	delete fromURLDialog;
}

void MainWindowImpl::rssFeed()
{
	if (!addRSSFeed) {
		addRSSFeed = new AddRSSFeed(this);
	}
	addRSSFeed->show();
	addRSSFeed->activateWindow();
}

void MainWindowImpl::frameDiskStatistics_show_hide() //Показ/скрытие дисковой статистики
{
	if (comboBox->currentIndex()==3)
	{
		frameDiskStatistics->setVisible(true);
		return;
	}
	frameDiskStatistics->setVisible(false);
}

void MainWindowImpl::about()
{
	QMessageBox::about(this, tr("About LinTorrent"),
					   tr("<h2>LinTorrent 0.0</h2>"
						  "Copyright &copy; <a href=mailto:true_dr0n@truetorrents.net.ru>TRUE_Dr0n</a> 2009"));
}

void MainWindowImpl::changeEvent(QEvent *e)
{
	QMainWindow::changeEvent(e);
	switch (e->type()) {
	case QEvent::LanguageChange:
		retranslateUi(this);
		break;
//	case QEvent::Quit:
//		QMessageBox::information(this,"LinTorrent",tr("Bye!!!"));
	default:
		break;
	}
}
